package com.woniuxy.producer;

import com.woniuxy.util.RabbitMQConst;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DelayProducer {
    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送延迟消息
     * @param orderId 订单ID
     * @param delay 延迟时间(毫秒)
     */
    public void sendDelayMessage(String orderId, Integer delay) {
        rabbitTemplate.convertAndSend(
                RabbitMQConst.DELAY_EXCHANGE,
                RabbitMQConst.DELAY_ROUTING_KEY,
                orderId,
                message -> {
                    message.getMessageProperties().setDelay(delay);
//                    message.getMessageProperties().setExpiration(delay.toString());
                    return message;
                });
    }
}
